15
INTRODUÇÃO JAVA AUTHENTICATION AND AUTHORIZATION SERVICE Bruno Taboada 29/11/2010

Jaas apresentado

Embed Size (px)

Citation preview

INTRODUÇÃO JAVA AUTHENTICATION AND

AUTHORIZATION SERVICEBruno Taboada

29/11/2010

O que é JaaS?

• É um framework.• Altamente plugável.• Disponível desde v1.4.• Flexível.• Integrado a arquitetura de segurança da

plataforma.

Java Security Overview

JaaS Anatomia

Terminologia• Realm • Groups• User• Role (Chave de uma porta)• Principal (Identidade)• Subject• Credential

Flexibilidade Jaas

Subject EmpregadoPrincipal

GerentePrincipalSubject

Permissão 1

Permissão 2

Permissão 3

Adicionando as roles (JBoss AS 5.0.1).

RoleEmpregadoPrincipal

SubjectRoleGerentePri

ncipal

RoleAdministradorPrincipal

Group

Exemplo Policy File

1. grant codebase "file:./SampleAction.jar", Principal

2. sample.principal.SamplePrincipal “nomeDoPrincipal" {

3. permission java.util.PropertyPermission "java.home", "read";

4. permission java.util.PropertyPermission "user.home", "read";

5. permission java.io.FilePermission "foo.txt", "read";

6. };

Plugabilidade LoginModule Jboss AS

1. <application-policy name = "Exemplo">

2. <authentication>

3. <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" = "required">

4. <module-option name = "unauthenticatedIdentity">guest</module-option>

5. <module-option name = "dsJndiName">java:/MyDataSourceConfig</module-option>

6. <module-option name = "principalsQuery">Select passord from users where userid=?</module-option>

7. <module-option name = "rolesQuery">Select role, 'Roles' from user_roles where userid=?</module-option>

8. </login-module>

9. </authentication>

10. </application-policy

Controle de Acesso em EJB

1. @DeclareRoles({“ADMINIISTRADOR", “EMPREGADO"})2. @Stateless 3. public class PagamentoBean implements Pagamento{4. @Resource SessionContext ctx;

5. @RolesAllowed(" ADMINIISTRADOR ")6. public void reviewEmpregadoInfo(EmplInfo info) {7. oldInfo = ... Ler banco de dados;8. }

9. @RolesAllowed(" EMPREGADO ")10. public void updateEmpregadoInfo(EmplInfo info) {11. newInfo = ... update database;12. }13. }

Declarativa Baseada em Anatoções

Controle de Acesso em Servlet

1. <security-constraint>

2. <web-resource-collection>

3. <web-resource-name>Control Access</web-resource-name>

4. <http-method>PUT</http-method>

5. <http-method>DELETE</http-method>

6. <http-method>GET</http-method>

7. <http-method>POST</http-method>

8. <url-pattern>/ServletSample.do</url-pattern>

9. </web-resource-collection>

10. <auth-constraint>

11. <role-name>ADMINISTRADOR</role-name>

12. </auth-constraint>

13. </security-constraint>

14. <security-role>

15. <role-name>ADMINISTRADOR</role-name>

16. </security-role>

Declarativa baseada em arquivo

Controle de Acesso em Servlet

1. @WebServlet(name="AccessControlSample", urlPatterns={"/ServletSample.do"})

2. public class TutorialServlet extends HttpServlet {

3. protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

4. response.setContentType("text/html;charset=UTF-8");

5. PrintWriter out = response.getWriter();

6. try {

7. if(request.isUserInRole("ADMINISTRADOR")){

8. out.println("I´m Administrator");

9. }else{

10. throw ApplicationExcetionDenied("Access Denied");

11. }

12. } catch (Exception e) {

13. throw new ServletException(e);

14. } finally {

15. out.close();

16. }

17. }

18. }

Programática

Referências

• Java EE 6 Tutorial • All that JAAS in Java World

(http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-jaas.html?page=2)

• Jboss AS 4 R5 Documentação (http://docs.jboss.org/jbossas/jboss4guide/r5/html/)

• JAVA SE 6 Specification (http://www.jcp.org/en/jsr/detail?id=316)• Java 6 Security Guide

(http://download.oracle.com/javase/6/docs/technotes/guides/security/)

• http://www.jaasbook.com/

Na internet sobre jaas

• Algumas Opiniões encontradas na internet.(GUJ)• “JAAS é legal por que por ser padrão, mas será que

não da para ser mais maleável? ”• “O JAAS é assim mesmo, rígido, inflexível,

configurableableable, etc... ”• “O jaas é um pouco limitado e cheio de restrições ”

• Eu também quero dar a minha.

Conclusão

• Robusto.• Plataforma Built-in.• Flexível.• Complexidade de implementação média.• Possui especificação elaborada por grandes

especialista no assunto.