finally, ee security api jsr 375

80
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 1

Upload: alex-kosowski

Post on 19-Jan-2017

9.921 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 1

Page 2: Finally, EE Security API JSR 375

Finally, EE Security API JSR 375

Alex Kosowski JSR 375 Specification Lead WebLogic Server Security

Page 3: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3

Safe Harbor Statement

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Page 4: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4

Agenda

§ Motivations

§ A New JSR

§  Ideas

§ Get Involved

§ Q & A

Page 5: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5

Agenda

§ Motivations

§ A New JSR

§  Ideas

§ Get Involved

§ Q & A

Page 6: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6

Why a Java EE Security API JSR?

§ EE 8 survey results § 4500 total responses § Priorities Pie Chart

Page 7: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7

What’s wrong with Java EE Security?

"The ultimate goal is to have basic security working without the need of any kind of vendor specific configuration, deployment descriptors, or whatever. ” – Arjan Tijms “[The EE security] model is problematic in cloud/PaaS environments where developers do not necessarily have easy access to non-standard vendor runtime features and a self-contained application is much easier to manage.” – Reza Rahman

The community says…

Page 8: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 8

What’s wrong with Java EE Security?

§  Java EE Security viewed as not portable, abstract/confusing, antiquated

§ Doesn’t fit cloud app developer paradigm: requires app server configuration

§ Losing value to non-standard 3rd Party Frameworks…less likely to move back to Java EE when requirements increase

Page 9: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 9

What to do?

§ Plug the portability holes § Modernize

–  Context Dependency Injection (CDI) §  Intercept at Access Enforcement Points: POJO methods

–  Expression Language (EL) §  Enable Access Enforcement Points with complex rules

§ App Developer Friendly –  Common security configurations not requiring server changes –  Annotation defaults not requiring XML

Page 10: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 10

Agenda

§ Motivations

§ A New JSR

§  Ideas

§ Get Involved

§ Q & A

Page 11: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 11

JSR 375 History

§ August 2014: First proposed to Oracle Java EE Architects § December 2014: Approved by JCP § Expert Group nominations:

–  EE API veterans: many JSRs, many years struggling with Security API –  3rd party security framework creators/developers –  EE platform security implementers

§ March 2015: Expert Group started discussions

Page 12: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 12

JSR 375 – Expert Group

Name Representing

Adam Bien Individual

David Blevins Tomitribe

Rudy De Busscher Individual

Ivar Grimstad Individual

Les Hazlewood Stormpath, Inc.

Will Hopkins Oracle

Werner Keil Individual

Page 13: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 13

JSR 375 – Expert Group

Name Representing

Matt Konda Jemurai

Alex Kosowski Oracle

Darran Lofthouse RedHat

Jean-Louis Monteiro Tomitribe

Ajay Reddy IBM

Pedro Igor Silva RedHat

Arjan Tijms ZEEF

Page 14: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 14

JSR 375 History

§  In first month, expert group had an EXPLOSION of activity –  Lot of Brainstorming! –  237 messages on EG mailing list –  81 commits in Github playgrounds for examples and proposals –  24 JIRA issues

Page 15: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 15

Agenda

§ Motivations

§ A New JSR

§  Ideas

§ Get Involved

§ Q & A

Page 16: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 16

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 17: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 17

Ideas To modernize, standardize, simplify

Identity Store

Authentication Mechanism Security Context Authorization

Interceptors

Role/Permission Assignment

Password Aliasing

Page 18: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 18

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 19: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 19

Ideas - Terminology

§ EG discussions revealed inconsistency in security API terms § Different EE containers have different names for the same concepts § When “something” gets authenticated, is that something a…

–  A User? (e.g. HttpServletRequest.getUserPrincipal) –  A Caller? (e.g. EJBContext.getCallerPrincipal)

§ What is a group? –  A group of users? –  A permission –  Vs Role?

Page 20: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 20

Ideas - Terminology

§ What is that “something” where identities are stored? –  security provider (WebLogic) –  realm (Tomcat, some hints in Servlet spec) –  (auth) repository –  (auth) store –  login module (JAAS) –  identity manager (Undertow) –  authenticator (Resin, OmniSecurity, Seam Security) –  authentication provider (Spring Security) –  identity provider

Page 21: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 21

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 22: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 22

Use Case

§ Application manages its own users and groups § Application needs to authenticate users in order to assign Roles § Application authenticates based on application-domain models § Application needs to use an authentication method not supported on

the server, like OpenID Connect § Developer wants to use portable EE Authentication standard

API for Authentication Mechanism

Page 23: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 23

Current Solutions

§ Proprietary server support § 3rd party security frameworks provide authentication §  JASPIC: Java Authentication Service Provider Interface for Containers

API for Authentication Mechanism

Page 24: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 24

JASPIC

§  Java Authentication Service Provider Interface for Containers §  JSR 196, Maintenance Release 1.1, in 2013 § Standardized, portable, thin, low-level authentication framework § Extensible from within an application §  Integrates with the container to build an authenticated Subject §  Implement any authentication method

Page 25: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 25

JASPIC Server Auth Module

public interface ServerAuthModule { public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler, Map options) throws AuthException; public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject); public Class<?>[] getSupportedMessageTypes(); public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject); public void cleanSubject(MessageInfo messageInfo, Subject subject); }

Page 26: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 26

JASPIC Per-Application Installation

ServletContextListener

AuthConfigFactory

AuthConfigProvider

ServerAuthConfig

ServerAuthContext

ServerAuthModule

Page 27: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 27

Ideas – Simple ServerAuthModule Installation

ServletContextListener

AuthConfigFactory

AuthConfigProvider

ServerAuthConfig

ServerAuthContext

ServerAuthModule

ServletContextListener

Page 28: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 28

Ideas – Simple ServerAuthModule Installation

@WebListener public class SamRegistrationListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { Jaspic.registerServerAuthModule(new TokenAuthModule(), sce.getServletContext()); } @Override public void contextDestroyed(ServletContextEvent sce) { } }

Page 29: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 29

Ideas – Simple ServerAuthModule Installation

@Authenticator("org.acme.TokenAuthModule") @WebServlet("/SimpleServlet") @ServletSecurity(@HttpConstraint(rolesAllowed = {"manager"})) public class SimpleServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("my GET"); } }

Page 30: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 30

Ideas – Profile Specific Helper Classes

public class BasicServerAuthModule implements ServerAuthModule { public void initialize(…) throws AuthException { … } public Class<?>[] getSupportedMessageTypes() { … } public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException { … } public void cleanSubject(MessageInfo messageInfo, Subject subject) throws AuthException { … } public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException { final HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage(); … }

Page 31: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 31

Ideas – Profile Specific Helper Classes

public class BasicServerAuthModule extends HttpServerAuthModule { public AuthStatus validateHttpRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthException { … } }

Page 32: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 32

Ideas – Profile Specific Helper Classes

public class BasicServerAuthModule extends HttpServerAuthModule { public AuthStatus validateHttpRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthException { final String header = request.getHeader("Authorization"); final String[] credentials = parseCredentials(header); final String username = credentials[0]; final String password = credentials[1]; if (!"snoopy".equals(username) || !"woodst0ck".equals(password)) { return FAILURE; } // No callbacks required!!! return httpMessageContext.notifyContainerAboutLogin( "snoopy", // the groups/roles of the authenticated user Arrays.asList("RedBaron", "JoeCool", "MansBestFriend")); }

Page 33: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 33

Ideas – Standardized Authenticators

@Authenticator("javax.security.authenticator.OpenIDConnect") @WebServlet("/SimpleServlet") @ServletSecurity(@HttpConstraint(rolesAllowed = {"manager"})) public class SimpleServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("my GET"); } }

§ OpenID Connect ServerAuthModule

Page 34: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 34

Ideas – Authentication Events § Throw standardized CDI events at important moments

–  PreAuthenticate Event –  PostAuthenticate Event –  PreLogout Event –  PostLogout Event

§ Possible uses: –  Tracking number of logged-in users –  Tracking failed login attempts per account –  Side effects, like creating a new local user after initial successful

authentication via a remote authentication provider –  Loading application-specific user preferences

Page 35: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 35

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 36: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 36

Use Case

§ Application manages its own users and groups § Need to access a repository of identities, like users § Users may be stored in app-specified repository (e.g. LDAP) § Users are managed without access to server configuration

API for Identity Store

Page 37: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 37

Survey Results API for Identity Store

Should we simplify JASPIC?

'Should we simplify authorization by introducing an EL-enabled authorization annotation?

'Should we standardize on requirements for simple security providers and their configuration?

''Approximately'58%'thought'we'should'add'support'for'password'aliases,'including'the'ability'to'provision'credentials'along'with'the'application.''70%'thought'that'we'should'standardize'group`to`role'mapping.''53%'thought'we'should'simplify'JASPIC'authentication.''67%'thought'that'we'should'simplify'authorization'and'make'it'more'flexible'by'introducing'EL`based'authorization'annotations,'introducing'a'capability'more'general'than'use'of'@RolesAllowed'and'simpler'than'use'of'interceptors'to'do'programmatic'authorization.''65%'thought'we'should'standardize'on'requirements'for'simple'security'providers'and'their'configuration.'

Page 38: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 38

Current Solutions

§ No Java EE support § Only proprietary server support § 3rd party security frameworks provide user/group APIs

API for Identity Store

Page 39: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 39

Ideas – Identity Store public interface Identity { String getUsername(); char[] getPassword(); boolean isAccountExpired(); boolean isAccountLocked();

boolean isPasswordExpired(); boolean isEnabled(); IdentityAttributeValue getAttribute(String name); } public interface IdentityAttributeValue { String getValue(); String getMetaInfo(String name); }

Page 40: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 40

Ideas – Identity Store public interface IdentityStore{ Identity loadIdentityByName(String name); void changePassword(char[] oldPassword, char[] newPassword); void createIdentity(Identity user); void deleteIdentity(String name);

void updateIdentity(Identity identity); boolean identityExists(String name); void createGroup(String group); void deleteGroup(String group); void addIdentityToGroup(String name, String group); void removeIdentityFromGroup(String name, String group); boolean isIdentityInGroup(String name, String group); List<String> getIdentityGroups(String name); }

Page 41: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 41

Ideas – Identity Store

IdentityStore

LDAP Server

Identity

DB File

Page 42: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 42

Ideas – Identity Store

@LdapIdentityStore(name=“java:app/prodIdentityStore”, ldapUrl=“ldap://blah”, ldapUser=“ElDap”,ldapPassword=“welcome”)

public class MyAuthenticator {

@Resource(lookup=“java:app/prodIdentityStore”) private IdentityStore identityStore;

private boolean isAccountEnabled(String username) { return identityStore.loadUserByUsername(username).isEnabled(); } … }

Page 43: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 43

Ideas – Identity Store

@EmbeddedIdentityStore(name=“java:app/devIdentityStore”,

{@Identity(username="ray", password="secret", groups="admin"),

@Identity(username="jo", password="secret", groups="user"),

@Identity(username="sam", password="secret", groups="user")})

@DatabaseIdentityStore(name=“java:app/testIdentityStore”,

lookup="somedatabase",

userQuery="SELECT password FROM principals WHERE username=?",

groupQuery="SELECT group FROM groups where username=?", ...)

Page 44: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 44

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 45: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 45

Use Case

§ Application uses passwords to access resources like LDAP and DB § Passwords stored in annotations, deployment descriptors § Best practices dictate that passwords are never stored in clear text § Need a portable way to protect stored passwords

API for Password Aliasing

Page 46: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 46

Survey Results

§ Deferred from Java EE 7

API for Password Aliasing

Should we standardize access to log messages by applications?

'''Respondents'strongly'supported'standardizing'use'of'java.util.logging'by'applications,'standardizing'the'management'of'log'files,'and'standardizing'the'logging'configuration'for'application'loggers.''A'majority'of'respondents'also'supported'standardizing'the'names'of'loggers'used'by'the'application'server,'the'format'of'log'files,'and'the'access'to'log'messages'by'applications.''Of'the'small'fraction'of'participants'who'added'comments,'most'of'these'strongly'urged'for'improvements'in'logging'–'either'by'the'revision'of'java.util.logging,'or'replacement'of'its'use'by'either'slf4j,''slf4j'with'LogBack,'or'log4j.''''Security''Most'of'the'suggested'improvements'in'the'security'area'received'strong'support.''Should we add support for password aliases (including the ability to provision credentials along with the application)?

'Should we standardize group-to-role mapping?

Page 47: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 47

Current Solutions

§ No Java EE support § Proprietary server support, e.g. GlassFish § 3rd party security framework support for embedded password

encryption, not aliasing

API for Password Aliasing

Page 48: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 48

Ideas – Password Aliasing § For annotations @DataSourceDefinition( name="java:app/jdbc/test", user="root", password="${ALIAS=password}",…)

§ For deployment descriptors

<data-source> <name>java:app/env/testDS</name> <user>APP</user> <password>${ALIAS=password}</password>

… </data-source>

Page 49: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 49

Ideas – Password Aliasing

${ALIAS=token} "mysecret"

Resolved when used

Cleared when done

Page 50: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 50

Ideas – Password Aliasing

Password Alias Archive

Page 51: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 51

Ideas – Password Aliasing

§ For configuration: Annotations, Deployment Descriptors § Secure credentials archive for bundling the alias and actual password

values with applications § Platform consumes the credentials archive upon deployment § Standard tooling for CRUD operations on the credential archive, e.g.

keytool

Page 52: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 52

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 53: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 53

Use Case

§ Application manages its own users and groups § Application needs to assign roles (i.e., authorities, permissions) to

users and groups, based on application-specific model § Users may be stored in app-specified repository (e.g. LDAP) § Users are managed without access to server configuration

API for Role/Permission Assignment

Page 54: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 54

Survey Results API for Role/Permission Assignment

Should we standardize access to log messages by applications?

'''Respondents'strongly'supported'standardizing'use'of'java.util.logging'by'applications,'standardizing'the'management'of'log'files,'and'standardizing'the'logging'configuration'for'application'loggers.''A'majority'of'respondents'also'supported'standardizing'the'names'of'loggers'used'by'the'application'server,'the'format'of'log'files,'and'the'access'to'log'messages'by'applications.''Of'the'small'fraction'of'participants'who'added'comments,'most'of'these'strongly'urged'for'improvements'in'logging'–'either'by'the'revision'of'java.util.logging,'or'replacement'of'its'use'by'either'slf4j,''slf4j'with'LogBack,'or'log4j.''''Security''Most'of'the'suggested'improvements'in'the'security'area'received'strong'support.''Should we add support for password aliases (including the ability to provision credentials along with the application)?

'Should we standardize group-to-role mapping?

Page 55: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 55

Current Solutions

§ No Java EE support § Only proprietary server support § 3rd party security frameworks provide role/authority/permission APIs

API for Role/Permission Assignment

Page 56: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 56

Ideas – Standardized Role Mapping

§ Support in Deployment Descriptors, e.g. web.xml

<security-role-map> <!-- Role name as set/returned by Authentication Module --> <group>MANAGER</group> <!-- Role name for mapping --> <role-name>EDIT_ACCOUNTS</role-name> </security-role-map>

<!– One-to-one group to role mapping --> <security-role-map groupToRoleMapping="false" />

Page 57: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 57

Ideas – Role Mapping Annotation

@EmbeddedRoleMapper( users={ @RoleMap(user=“foo”,roles=“admin”), @RoleMap(group=“admin”,roles={“admin”,”manager”}) } ) public class MyServlet { }

Page 58: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 58

Ideas – Dynamic Role Mapping public interface RoleMapper { void grantRoleToUser(String username, String role); void revokeRoleFromUser(String username, String role); boolean hasRoleForUser( String username, String role, boolean includeGroups);

List<String> getRolesForUser( String username, boolean includeGroups); List<String> getUsersWithRole( String role, boolean includeGroups); void grantRoleToGroup(String group, String role); void revokeRoleFromGroup(String group, String role); boolean hasRoleForGroup(String group, String role); List<String> getRolesForGroup(String group); List<String> getGroupsWithRole(String role); }

Page 59: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 59

Ideas – Dynamic Role Mapping @Inject RoleMapper roleMapper; roleMapper.grantRoleToGroup("Manager", "EDIT_ACCOUNTS");

boolean has = roleMapper.hasRoleForGroup("Manager", "CLOSE_ACCT"); List<String> roles = roleMapper.getRolesForGroup("Manager"); List<String> groups = roleMapper.getGroupsWithRole("VIEW_ACCOUNTS");

Page 60: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 60

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 61: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 61

Use Case

§ Application needs to access the security API –  To get the authenticated user –  To check roles –  To invoke runAs.

§ Application needs the same API to access security context, regardless of container

API for Security Context

Page 62: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 62

Current Solutions

§ No Java EE support § 3rd party security frameworks provide a security context

API for Security Context

Page 63: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 63

Current Solutions

@Singleton

public class MyEjb {

@Resource

private SessionContext sessionContext;

public String sayHello() {

if (sessionContext.isCallerInRole("admin")) {

return "Hello World!";

}

throw new SecurityException("User is unauthorized.");

}

}

Page 64: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 64

Current Solutions

public class MyServlet extends HttpServlet {

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {

if (request.isUserInRole("admin")) {

// do something

}

throw new ServletException("User is unauthorized.");

}

}

Page 65: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 65

Current Solutions

@RequestScoped

public class MyCdiBean {

// Oh snap! No SecurityContext class for CDI

}

Page 66: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 66

Current Solutions

public class MyJaxRsService {

@GET

@Produces("text/plain;charset=UTF-8")

@Path("/hello")

public String sayHello(@Context SecurityContext sc) {

if (sc.isUserInRole("admin")) {

return "Hello World!";

}

throw new SecurityException("User is unauthorized.");

}

}

Page 67: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 67

Ideas – Security Context public interface SecurityContext {

String getUserPrincipal();

boolean isUserInRole(String role);

List<String> getAllUsersRoles();

boolean isAuthenticated();

boolean isUserInAnyRole(List<String> roles);

boolean isUserInAllRoles(List<String> roles);

void login(Object request, Object response);

void login(Map map);

void logout();

void runAs(String role);

boolean hasAccessToResource();

boolean hasAccessToBeanMethod();

}

Page 68: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 68

Ideas – Security Context § For all managed beans: CDI, Servlet, EJB, JAX-RS, etc

public class MyFutureCdiBean {

@Inject

private SecurityContext securityContext;

public String sayHello() {

if (securityContext.isUserInRole("admin")) {

return "Hello World!";

}

throw new SecurityException("User is unauthorized.");

}

}

Page 69: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 69

Ideas

§ Terminology § API for Authentication Mechanism § API for Identity Store § API for Password Aliasing § API for Role/Permission Assignment § API for Security Context § API for Authorization Interceptors

To modernize, standardize, simplify

Page 70: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 70

Use Case

§ Application needs to restrict specific methods to authorized users § Application-model rules are used to make access decisions § Role is insufficient

API for Authorization Interceptors

Page 71: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 71

Survey Results API for Authorization Interceptors

Should we extract Facelets from JSF as the standard template engine for Java EE?

'''Should we standardize on another existing technology?

'Only'a'small'fraction'of'respondents'answered'the'open`ended'"If'so,'which?"'part'of'this'last'question.''Thymeleaf,'Freemarker,'and'Velocity'were'the'most'frequently'mentioned'here.'''''CDI''The'next'four'questions'focused'on'continued'CDI'alignment.''This'was'one'of'the'focus'areas'of'Java'EE'7.''Should we consider adding Security Interceptors in Java EE 8?

Should we simplify JASPIC?

'Should we simplify authorization by introducing an EL-enabled authorization annotation?

'Should we standardize on requirements for simple security providers and their configuration?

''Approximately'58%'thought'we'should'add'support'for'password'aliases,'including'the'ability'to'provision'credentials'along'with'the'application.''70%'thought'that'we'should'standardize'group`to`role'mapping.''53%'thought'we'should'simplify'JASPIC'authentication.''67%'thought'that'we'should'simplify'authorization'and'make'it'more'flexible'by'introducing'EL`based'authorization'annotations,'introducing'a'capability'more'general'than'use'of'@RolesAllowed'and'simpler'than'use'of'interceptors'to'do'programmatic'authorization.''65%'thought'we'should'standardize'on'requirements'for'simple'security'providers'and'their'configuration.'

Page 72: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 72

Current Solutions

§ EE authorization has no rule based authorization, only role based § 3rd party security frameworks provide rule, role and permission based

APIs

API for Authorization Interceptors

Page 73: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 73

Ideas – EL Authorization Rules

§ Expression Language rule would have access to managed beans for SecurityContext and InvocationContext

@ EvaluateSecured("security.hasRoles('MANAGER') && schedule.nowIsOfficeHrs") void transferFunds() {..};

Page 74: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 74

Ideas – EL Authorization Rules § EL Authorization rules centrally managed in a repository @LdapAuthorizationRules ( name="java:app/accountAuthRules", ldapUrl="ldap://blah", ldapUser="ElDap", ldapPassword=“mysecret” ) public class MyBean { @ EvaluateSecured( ruleSourceName="java:app/accountAuthRules", rule="transferFunds") void transferFunds() {..}; … }

Page 75: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 75

Ideas – AccessDecisionVoter

§ A user-defined class for making access decisions @Secured(AccountAccessDecisionVoter.class) void transferFunds() {..};

Page 76: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 76

Ideas – AccessDecisionVoter

public class AccountAccessDecisionVoter implements AccessDecisionVoter { @Override public void checkPermission(AccessDecisionVoterContext ctx, Set<SecurityViolation> violations) { // Check for violations Method method = ctx.<InvocationContext>getSource().getMethod(); … violations.add(new SecurityViolation("Sorry, not allowed")); } }

Page 77: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 77

Agenda

§ Motivations

§ A New JSR

§  Ideas

§ Get Involved

§ Q & A

Page 78: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 78

Get Involved

§ Project Page: The starting point to all resources https://java.net/projects/javaee-security-spec

§ Users List: Subscribe and contribute

[email protected] § Github Playground: Fork and Play!

https://github.com/javaee-security-spec/javaee-security-proposals

Page 79: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 79

Q/A

Page 80: Finally, EE Security API JSR 375

Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 80