6 Security v2
6 Security v2
What are authentication and authorization? Which must come first? .............................. 2
Authorization........................................................................................................................ 2
Salting.................................................................................................................................... 8
Why do you need method security? What type of object is typically secured at the
method level (think of its purpose not its Java type) ............................................................ 8
@PreAuthorize ..................................................................................................................... 9
@RolesAllowed .................................................................................................................. 10
Authorization
Authorization is the process of determining that a user is permitted to do something that the
user is attempting to do. Authorization is the process of specifying access rights to resources.
Authorization typically involves the following two separate aspects that combine to describe
the accessibility of the secured system:
- The first is the mapping of an authenticated principal to one or more authorities (often
called roles);
- The second is the assignment of authority checks to secured resources of the system.
Which must come first?
Unless there is some type of authorization that specifies what resources and/or functions that
can be accessed by anonymous users, authentication must always come before authorization.
Salting
A salt used when calculating the hash-value for a password is a sequence of random bytes that
are used in combination with the cleartext password to calculate a hash-value. The salt is stored
in cleartext alongside the password hash-value and can later be used when calculating hash-
values for user-supplied passwords at login.
@PreAuthorize
The @PreAuthorize annotation allows for specifying access constraints to a method using the
Spring Expression Language (SpEL). These constraints are evaluated prior to the method being
executed and may result in execution of the method being denied if the constraints are not
fulfilled. The @PreAuthorize annotation is part of the Spring Security framework.
In order to be able to use @PreAuthorize, the prePostEnabled attribute in the
@EnableGlobalMethodSecurity annotation needs to be set to true.
@RolesAllowed
The @RolesAllowed annotation has its origin in the JSR-250 Java security standard. This
annotation is more limited than the @PreAuthorize annotation in that it only supports role-
based security.
In order to use the @RolesAllowed annotation the library containing this annotation needs to
be on the classpath, as it is not part of Spring Security. In addition, the jsr250Enabled attribute
of the @EnableGlobalMethodSecurity annotation need to be set to true.
Spring security offers a security tag library for JSP, would you recognize
it if you saw it in an example?
First of all, if the Spring Security JSP tags are to be used in a JSP then the security taglib must
be declared in the JSP in question using the following statement: