diff --git a/restservice/src/main/java/com/plannaplan/App.java b/restservice/src/main/java/com/plannaplan/App.java index 30f7817..b5afea8 100755 --- a/restservice/src/main/java/com/plannaplan/App.java +++ b/restservice/src/main/java/com/plannaplan/App.java @@ -21,6 +21,9 @@ import org.springframework.scheduling.annotation.EnableScheduling; import com.plannaplan.services.ConfiguratorService; +/** + * Root class of Application. + */ @SpringBootApplication @EnableScheduling public class App { diff --git a/restservice/src/main/java/com/plannaplan/Logo.java b/restservice/src/main/java/com/plannaplan/Logo.java index 3573082..229ab78 100755 --- a/restservice/src/main/java/com/plannaplan/Logo.java +++ b/restservice/src/main/java/com/plannaplan/Logo.java @@ -3,6 +3,9 @@ package com.plannaplan; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +/** + * Class to generate logo string on start application and make logs info + */ public class Logo { public static final String ANSI_RESET = "\u001B[0m"; @@ -35,6 +38,11 @@ ANSI_RESET; } + /** + * return init string to log + * @param isDev is spring profile dev + * @return string to print in log + */ public static String getInitInfo(boolean isDev){ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); LocalDateTime now = LocalDateTime.now(); @@ -45,6 +53,11 @@ ANSI_RESET; return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + " plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "prod" + ANSI_RESET +"]"; } + /** + * return start string to log + * @param isDev is spring profile dev + * @return string to print in log + */ public static String getStartedInfo(boolean isDev){ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); LocalDateTime now = LocalDateTime.now(); diff --git a/restservice/src/main/java/com/plannaplan/Swagger2Config.java b/restservice/src/main/java/com/plannaplan/Swagger2Config.java index 19ad14d..f3796e0 100755 --- a/restservice/src/main/java/com/plannaplan/Swagger2Config.java +++ b/restservice/src/main/java/com/plannaplan/Swagger2Config.java @@ -18,6 +18,9 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +/** + * Config class of Swagger to generate rest api documentation + */ @Configuration @EnableSwagger2 public class Swagger2Config extends WebMvcConfigurationSupport { diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java index 313d6d7..75a4269 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java @@ -8,6 +8,9 @@ import com.plannaplan.types.GroupType; import io.swagger.annotations.ApiModel; +/** + * Assignment entity api response + */ @ApiModel(description = "Response shows information about given assigment to course.", value = "AssignmentResponse") public class AssignmentResponse { private Long id; @@ -15,6 +18,11 @@ public class AssignmentResponse { private GroupWithCapacityResponse classes; private GroupWithCapacityResponse lecture; + /** + * @param course course entity + * @param lecture lecture Groups entity + * @param classes class Groups entity + */ public AssignmentResponse(Course course, Groups lecture, Groups classes) { this.id = course.getId(); this.name = course.getName(); @@ -22,6 +30,13 @@ public class AssignmentResponse { this.classes = classes == null ? null : new GroupWithCapacityResponse(classes); } + /** + * @param course course entity + * @param lecture lecture Groups entity + * @param classes class Groups entity + * @param ammounts map with ammounts key - group id, value - ammounts of taken + * places + */ public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap ammounts) { this.id = course.getId(); this.name = course.getName(); @@ -29,28 +44,51 @@ public class AssignmentResponse { this.classes = classes == null ? null : new GroupWithCapacityResponse(classes, ammounts.get(classes.getId())); } + /** + * + * @param course course entity + * @param group class/lecture entity + */ public AssignmentResponse(Course course, Groups group) { this(course, group.getType() == GroupType.LECTURE ? group : null, group.getType() == GroupType.CLASS ? group : null); } + /** + * @param course course entity + * @param group class/lecture entity + * @param ammounts map with ammounts key - group id, value - ammounts of taken + * places + */ public AssignmentResponse(Course course, Groups group, HashMap ammounts) { this(course, group.getType() == GroupType.LECTURE ? group : null, group.getType() == GroupType.CLASS ? group : null, ammounts); } + /** + * @return Lecture in api response forms + */ public GroupWithCapacityResponse getLecture() { return this.lecture; } + /** + * @return Class in api response forms + */ public GroupWithCapacityResponse getClasses() { return this.classes; } + /** + * @return String course name + */ public String getName() { return this.name; } + /** + * @return db assignment id + */ public Long getId() { return this.id; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java index 9c91e1e..bd18a4b 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionResponse.java @@ -5,6 +5,9 @@ import com.plannaplan.entities.Commision; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +/** + * Commision api response + */ @ApiModel(description = "Response shows information about commision.", value = "CommisionResponse") public class CommisionResponse { @ApiModelProperty(value = "ID created by database") @@ -19,6 +22,9 @@ public class CommisionResponse { @ApiModelProperty(value = "Timestamp where the user commit the commision") private String commisionDate; + /** + * @param commision commision to map to api response + */ public CommisionResponse(Commision commision) { this.id = commision.getId(); this.commisionDate = commision.getCommisionDate().toString(); @@ -27,18 +33,30 @@ public class CommisionResponse { : null; } + /** + * @return get Commiter user as api response + */ public UserResponse getCommiter() { return commiter; } + /** + * @return get Owner user as api response + */ public UserResponse getOwner() { return owner; } + /** + * @return when commision was created string formated + */ public String getCommisionDate() { return commisionDate; } + /** + * @return db id + */ public Long getId() { return id; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java index 435f754..0e7c109 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java @@ -11,12 +11,18 @@ import com.plannaplan.entities.Commision; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +/** + * Commision With Groups api Response. It extends CommisionResponse repsone + */ @ApiModel(description = "Response shows information about commision and its groups.", value = "CommisionWithGroupsResponse") public class CommisionWithGroupsResponse extends CommisionResponse { @ApiModelProperty(value = "List of groups ids in databse that belongs to commision") private List groups; + /** + * @param commision commision to map to api response + */ public CommisionWithGroupsResponse(Commision commision) { super(commision); this.groups = commision.getAssignments().stream().filter(Objects::nonNull) @@ -29,6 +35,9 @@ public class CommisionWithGroupsResponse extends CommisionResponse { }).collect(Collectors.toList()); } + /** + * @return lsit of fetured groups ids + */ public List getGroups() { return groups; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CourseWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CourseWithGroupsResponse.java index 6b8107f..a4bb3f7 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CourseWithGroupsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CourseWithGroupsResponse.java @@ -5,21 +5,36 @@ import java.util.List; import io.swagger.annotations.ApiModel; +/** + * Course respose with all realted groups as api response. Alse needs to specify + * what type of Groups api response will be kept here. For excmaple it can be + * GroupDefaultRespnse + */ @ApiModel(description = "Response shows information about groups to given course.", value = "CourseWithGroupsResponse") -public class CourseWithGroupsResponse { +public class CourseWithGroupsResponse { private List lectures = new ArrayList<>(); private List classes = new ArrayList<>(); - public CourseWithGroupsResponse(List classes, List lectures ){ + /** + * @param classes realted classes Groups instance + * @param lectures realted lectures Groups instance + */ + public CourseWithGroupsResponse(List classes, List lectures) { this.lectures = lectures; this.classes = classes; } + /** + * @return realted classes Groups instance + */ public List getClasses() { return this.classes; } + /** + * @return realted lectures Groups instance + */ public List getLectures() { return this.lectures; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CoursesDefaultResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CoursesDefaultResponse.java index 12f5671..83277a9 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CoursesDefaultResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CoursesDefaultResponse.java @@ -5,9 +5,21 @@ import com.plannaplan.responses.models.abstracts.CoursesResponse; import io.swagger.annotations.ApiModel; +/** + * Courses Default Api Response. It extends abstract response - CoursesResponse. + * It was one of first repsones created in system. Later we resigned from + * asbstract and used settig + * spring.jackson.default-property-inclusion = NON_NULL in + * properties instead. + */ @ApiModel(description = "Response shows information about course.", value = "CoursesDefaultResponse") public class CoursesDefaultResponse extends CoursesResponse { + /** + * create new instance + * + * @param course course to map to api response + */ public CoursesDefaultResponse(Course course) { super(course); } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java index 62820fa..cf5eb17 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java @@ -9,12 +9,24 @@ import com.plannaplan.types.GroupType; import io.swagger.annotations.ApiModel; +/** + * Courses With Groups Api Response . It extends abstract response - + * CoursesResponse. It was one of first repsones created in system. Later we + * resigned from asbstract and used settig + * spring.jackson.default-property-inclusion = NON_NULL in + * properties instead. + */ @ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse") public class CoursesWithGroupsResponse extends CoursesResponse { private List lectures = new ArrayList<>(); private List classes = new ArrayList<>(); + /** + * create new instance + * + * @param course course to map to api response + */ public CoursesWithGroupsResponse(Course course) { super(course); course.getGroups().stream().forEach(group -> { @@ -26,6 +38,12 @@ public class CoursesWithGroupsResponse extends CoursesResponse { }); } + /** + * + * @param course course to map to api response + * @param lectures list of api resposnes of lectures + * @param classes list of api resposnes of classes + */ public CoursesWithGroupsResponse(Course course, List lectures, List classes) { super(course); @@ -33,10 +51,16 @@ public class CoursesWithGroupsResponse extends CoursesResponse { this.classes = classes; } + /** + * @return list of api resposnes of classes + */ public List getClasses() { return this.classes; } + /** + * @return list of api resposnes of lectures + */ public List getLectures() { return this.lectures; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/ExchangeResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/ExchangeResponse.java index 7e6057c..4a02a83 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/ExchangeResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/ExchangeResponse.java @@ -2,35 +2,72 @@ package com.plannaplan.responses.models; import com.plannaplan.entities.Exchange; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * Exchange proposal api repsonse + */ +@ApiModel(description = "Response shows information about user exchanges", value = "CourseWithGroupsResponse") public class ExchangeResponse { - private Long id; - private GroupDefaultResponse ownedAssignment; - private GroupDefaultResponse desiredGroup; + @ApiModelProperty(value = "Database id") + private Long id; + @ApiModelProperty(value = "Assignmetn that user want to trade") + private GroupDefaultResponse ownedAssignment; + @ApiModelProperty(value = "Group that user want to get") + private GroupDefaultResponse desiredGroup; - public ExchangeResponse(Exchange exchange){ - this.id = exchange.getId(); - this.ownedAssignment = new GroupDefaultResponse(exchange.getOwnedAssignment().getGroup()); - this.desiredGroup = new GroupDefaultResponse(exchange.getDesiredAssignment()); - } + /** + * creat new instance + * + * @param exchange entity to map to api repsone + */ + public ExchangeResponse(Exchange exchange) { + this.id = exchange.getId(); + this.ownedAssignment = new GroupDefaultResponse(exchange.getOwnedAssignment().getGroup()); + this.desiredGroup = new GroupDefaultResponse(exchange.getDesiredAssignment()); + } + /** + * @return get api respondse of wanted byt user group + */ public GroupDefaultResponse getDesiredGroup() { return desiredGroup; } + + /** + * @param desiredGroup set api respondse of wanted byt user group + */ public void setDesiredGroup(GroupDefaultResponse desiredGroup) { this.desiredGroup = desiredGroup; } + + /** + * @return get api respondse of owned user group + */ public GroupDefaultResponse getOwnedAssignment() { return ownedAssignment; } + + /** + * @param ownedAssignment set api respondse of owned user group + */ public void setOwnedAssignment(GroupDefaultResponse ownedAssignment) { this.ownedAssignment = ownedAssignment; } + + /** + * @return database id + */ public Long getId() { return id; } + + /** + * @param id set database id + */ public void setId(Long id) { this.id = id; } - } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java index 2a16b91..3e16109 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java @@ -8,6 +8,9 @@ import com.plannaplan.types.GroupType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +/** + * Default api response for Groups entity + */ @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel(description = "Response shows information about given group.", value = "GroupDefaultResponse") public class GroupDefaultResponse { @@ -36,6 +39,11 @@ public class GroupDefaultResponse { @ApiModelProperty(value = "Value shows how many places is already taken by other students.") private Integer takenPlaces; + /** + * creat new entity + * + * @param group entity to map to api response + */ public GroupDefaultResponse(Groups group) { this.id = group.getId() != null ? group.getId() : null; this.day = group.getDay() != null ? group.getDay().label : -1; @@ -46,43 +54,77 @@ public class GroupDefaultResponse { this.type = group.getType() != null ? group.getType() : null; } + /** + * + * @param group entity to map to api response + * @param takenPlaces ammount of taken places for group by other users + */ public GroupDefaultResponse(Groups group, int takenPlaces) { this(group); this.takenPlaces = takenPlaces; } + /** + * creat new entity + * + * @param assignment entity to map to api response + */ public GroupDefaultResponse(Assignment assignment) { this(assignment.getGroup()); } + /** + * @return what typew of group is this (lecture or class) + */ public GroupType getType() { return type; } + /** + * @return room where classes will take place + */ public String getRoom() { return room; } + /** + * @return name of group lecturer + */ public String getLecturer() { return lecturer; } + /** + * @return time when group is scheduled on + */ public String getTime() { return time; } + /** + * @return time when class ends + */ public String getEndTime() { return endTime; } + /** + * @return int what day is it. 0-6 (Monday - Sunday) + */ public int getDay() { return day; } + /** + * @return db id + */ public Long getId() { return id; } + /** + * @return ammount of taken places for group by other users + */ public Integer getTakenPlaces() { return this.takenPlaces; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GroupWithCapacityResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GroupWithCapacityResponse.java index 1ca9fc2..881dcfe 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/GroupWithCapacityResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/GroupWithCapacityResponse.java @@ -4,29 +4,57 @@ import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Groups; import io.swagger.annotations.ApiModel; +/** + * Group api response featuring group capacity + */ @ApiModel(description = "Response shows information about group with included capacity.", value = "GroupWithCapacityResponse") public class GroupWithCapacityResponse extends GroupDefaultResponse { private int capacity; + /** + * create new instance + * + * @param group entity to map to api response + */ public GroupWithCapacityResponse(Groups group) { super(group); this.capacity = group.getCapacity(); } + /** + * create new instance + * + * @param group entity to map to api response + * @param takenPlaces group taken places + */ public GroupWithCapacityResponse(Groups group, int takenPlaces) { super(group, takenPlaces); this.capacity = group.getCapacity(); } + /** + * create new instance + * + * @param assignment entity to map to api response + */ public GroupWithCapacityResponse(Assignment assignment) { this(assignment.getGroup()); } + /** + * create new instance + * + * @param assignment entity to map to api response + * @param takenPlaces group taken places + */ public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) { this(assignment.getGroup(), takenPlaces); } + /** + * @return group taken places + */ public int getCapacity() { return capacity; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java index 583619f..3bcec30 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java @@ -5,6 +5,9 @@ import com.plannaplan.entities.User; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +/** + * Response to show after successfully login cation + */ @ApiModel(description = "Response shows information about logged user.", value = "TokenResponse") public class TokenResponse { @ApiModelProperty(value = "user token used to verify requests") @@ -18,6 +21,9 @@ public class TokenResponse { @ApiModelProperty(value = "user unviersity email") private String email; + /** + * @param user user to be mapped to api response + */ public TokenResponse(User user) { this.id = user.getId(); this.authorityRole = user.getRole().toString(); @@ -26,22 +32,37 @@ public class TokenResponse { this.refreshToken = user.getRefreshToken(); } + /** + * @return user email + */ public String getEmail() { return email; } + /** + * @return user role in system + */ public String getAuthorityRole() { return authorityRole; } + /** + * @return db id + */ public Long getId() { return id; } + /** + * @return user token to authorize other requests + */ public String getToken() { return token; } + /** + * @return user refresh token + */ public String getRefreshToken() { return this.refreshToken; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/UserResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/UserResponse.java index ac606ac..6aa695a 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/UserResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/UserResponse.java @@ -4,6 +4,9 @@ import com.plannaplan.entities.User; import io.swagger.annotations.ApiModel; +/** + * Model for api response for user serach results. + */ @ApiModel(description = "Response shows information about user.", value = "UserResponse") public class UserResponse { @@ -12,6 +15,9 @@ public class UserResponse { private String surname; private String email; + /** + * @param user entity to be mapped to api response + */ public UserResponse(User user) { this.id = user.getId(); this.name = user.getName() != null ? user.getName() : ""; @@ -19,18 +25,30 @@ public class UserResponse { this.email = user.getEmail(); } + /** + * @return user email + */ public String getEmail() { return email; } + /** + * @return user surname + */ public String getSurname() { return surname; } + /** + * @return user name + */ public String getName() { return name; } + /** + * @return db id + */ public Long getId() { return id; } diff --git a/restservice/src/main/java/com/plannaplan/responses/models/abstracts/CoursesResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/abstracts/CoursesResponse.java index 6f1f916..903a451 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/abstracts/CoursesResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/abstracts/CoursesResponse.java @@ -2,20 +2,34 @@ package com.plannaplan.responses.models.abstracts; import com.plannaplan.entities.Course; +/** + * Course entity api response + */ public abstract class CoursesResponse { private Long id; private String name; + /** + * create instance + * + * @param course entity to map to api response + */ public CoursesResponse(Course course) { this.id = course.getId() != null ? course.getId() : null; this.name = course.getName() != null ? course.getName() : ""; } + /** + * @return course name + */ public String getName() { return name; } + /** + * @return db id + */ public Long getId() { return id; } diff --git a/restservice/src/main/java/com/plannaplan/security/AuthenticationFilter.java b/restservice/src/main/java/com/plannaplan/security/AuthenticationFilter.java index 3ebfe13..f9bcb26 100755 --- a/restservice/src/main/java/com/plannaplan/security/AuthenticationFilter.java +++ b/restservice/src/main/java/com/plannaplan/security/AuthenticationFilter.java @@ -17,6 +17,9 @@ import org.springframework.security.web.util.matcher.RequestMatcher; import static org.springframework.http.HttpHeaders.AUTHORIZATION; +/** + * Spring authentication filter class + */ public class AuthenticationFilter extends AbstractAuthenticationProcessingFilter { AuthenticationFilter(final RequestMatcher requiresAuth) { diff --git a/restservice/src/main/java/com/plannaplan/security/AuthenticationProvider.java b/restservice/src/main/java/com/plannaplan/security/AuthenticationProvider.java index e094488..a2bd294 100755 --- a/restservice/src/main/java/com/plannaplan/security/AuthenticationProvider.java +++ b/restservice/src/main/java/com/plannaplan/security/AuthenticationProvider.java @@ -16,6 +16,9 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; +/** + * Spring authentication provider + */ @Component public class AuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { @@ -25,8 +28,6 @@ public class AuthenticationProvider extends AbstractUserDetailsAuthenticationPro @Override protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { - // is being done in other task - } @Override diff --git a/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java b/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java index 7005438..ead5811 100755 --- a/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java +++ b/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java @@ -6,6 +6,9 @@ import com.plannaplan.types.UserRoles; import org.springframework.security.core.GrantedAuthority; +/** + * Users Roles for spring app + */ public enum AuthorityRoles implements GrantedAuthority { STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER"); @@ -20,6 +23,12 @@ public enum AuthorityRoles implements GrantedAuthority { return this.role; } + /** + * map buisness logic UserRoles enum to spring enum + * + * @param role buisness logic enum + * @return restservice AuthorityRoles enum + */ public static final Optional getAuthorityRole(UserRoles role) { switch (role) { case ADMIN: diff --git a/restservice/src/main/java/com/plannaplan/security/WebSecurityConfig.java b/restservice/src/main/java/com/plannaplan/security/WebSecurityConfig.java index cbeff0d..a5bbce8 100755 --- a/restservice/src/main/java/com/plannaplan/security/WebSecurityConfig.java +++ b/restservice/src/main/java/com/plannaplan/security/WebSecurityConfig.java @@ -16,9 +16,11 @@ import org.springframework.http.HttpStatus; import org.springframework.security.web.authentication.AnonymousAuthenticationFilter; import org.springframework.security.web.authentication.HttpStatusEntryPoint; +/** + * Spring config class for security + */ @Configuration @EnableWebSecurity - public class WebSecurityConfig extends WebSecurityConfigurerAdapter { private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher(new AntPathRequestMatcher("/api/**")); diff --git a/restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java b/restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java index 90b1f5e..01a72be 100755 --- a/restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java @@ -1,19 +1,36 @@ package com.plannaplan.security.cas; +/** + * Model to keep data from Cas response. It's important to remember that wee + * need to register our domain name in CAS in order to get this data. Otherwise + * CAS will retuned what user typed as login. + */ public class CasUserIdentity { private String usosId; private String email; - - public CasUserIdentity(String usosId, String email){ + + /** + * creates new instance + * + * @param usosId usosId retured from CAS + * @param email emial returned from CAS + */ + public CasUserIdentity(String usosId, String email) { this.usosId = usosId; this.email = email; } + /** + * @return string with usosid + */ public String getUsosId() { return usosId; - } + } + /** + * @return string with email + */ public String getEmail() { return email; - } + } } \ No newline at end of file diff --git a/restservice/src/main/java/com/plannaplan/security/cas/CasValidationExcepiton.java b/restservice/src/main/java/com/plannaplan/security/cas/CasValidationExcepiton.java index 3e6fec3..e53b99a 100755 --- a/restservice/src/main/java/com/plannaplan/security/cas/CasValidationExcepiton.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/CasValidationExcepiton.java @@ -1,9 +1,9 @@ package com.plannaplan.security.cas; +/** + * Exception to throw when cas didn't validate provided ticket + */ public class CasValidationExcepiton extends RuntimeException { - /** - * - */ private static final long serialVersionUID = 1L; public CasValidationExcepiton(String s) { diff --git a/restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java b/restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java index b091e42..3ef3562 100755 --- a/restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java @@ -1,6 +1,17 @@ package com.plannaplan.security.cas; +/** + * We can authorize in different contexts. For example if we rgister our domain + * we will get more info than on localhost. This abstraction let's us handle + * both cases based on spring profile + */ public interface CasValidator { - + + /** + * validate ticket (should be provided in costructor or by setter) + * + * @return CasUserIdentity instance with values from response or null if + * validation failed + */ CasUserIdentity validate(); } diff --git a/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java b/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java index 9a845df..be32736 100755 --- a/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java @@ -4,6 +4,10 @@ import org.jasig.cas.client.validation.Assertion; import org.jasig.cas.client.validation.Cas20ServiceTicketValidator; import org.jasig.cas.client.validation.TicketValidationException; +/** + * Cas Validator for UAM with domain registered for email and usosid as a + * repsonse + */ public class CustomUAMCasValidator implements CasValidator { private static String CAS_URL = "https://cas.amu.edu.pl/cas"; private static String EMAIL_FIELD = "mail"; @@ -11,31 +15,36 @@ public class CustomUAMCasValidator implements CasValidator { private String service; private String ticket; - public CustomUAMCasValidator(String service, String ticket){ + /** + * craste new instance + * + * @param service string with url of our service from where request began + * @param ticket ticket returned after user provided creeds on cas page + */ + public CustomUAMCasValidator(String service, String ticket) { this.service = service; this.ticket = ticket; } @Override public CasUserIdentity validate() { - /* - * TO DO - * Dodać case z CAS10/CAS20/CAS30 - */ final Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator(CustomUAMCasValidator.CAS_URL); try { final Assertion assertion = validator.validate(this.ticket, this.service); - + if (assertion == null) { - throw new CasValidationExcepiton("Validation failed. Assertion could not be retrieved for ticket " + ""); + throw new CasValidationExcepiton( + "Validation failed. Assertion could not be retrieved for ticket " + ""); } - final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID).toString(); - - final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD).toString(); + final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID) + .toString(); - return new CasUserIdentity(usosid,mail); + final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD) + .toString(); + + return new CasUserIdentity(usosid, mail); } catch (TicketValidationException e) { e.printStackTrace(); diff --git a/restservice/src/main/java/com/plannaplan/security/cas/DefaultUAMCasValidator.java b/restservice/src/main/java/com/plannaplan/security/cas/DefaultUAMCasValidator.java index e79a410..989c67f 100755 --- a/restservice/src/main/java/com/plannaplan/security/cas/DefaultUAMCasValidator.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/DefaultUAMCasValidator.java @@ -9,12 +9,21 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +/** + * Cas Validator for localhost and not registered dopmains + */ public class DefaultUAMCasValidator implements CasValidator { private static String CAS_URL = "https://cas.amu.edu.pl/cas"; private final CloseableHttpClient httpClient = HttpClients.createDefault(); private String service; private String ticket; + /** + * craste new instance + * + * @param service string with url of our service from where request began + * @param ticket ticket returned after user provided creeds on cas page + */ public DefaultUAMCasValidator(String service, String ticket) { this.service = service; this.ticket = ticket; @@ -39,13 +48,13 @@ public class DefaultUAMCasValidator implements CasValidator { } String res = result.substring(result.indexOf('\n') + 1); - return new CasUserIdentity(null,res); + return new CasUserIdentity(null, res); } } catch (Exception e) { - throw new CasValidationExcepiton("Cas Validation has failed."); + throw new CasValidationExcepiton("Cas Validation has failed."); } } } diff --git a/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json index ddf61f2..a106409 100755 --- a/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/restservice/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -14,6 +14,21 @@ "name": "plannaplan.email", "type": "java.lang.String", "description": "Email from which app sends message" + }, + { + "name": "plannaplan.apiurl", + "type": "java.lang.String", + "description": "Url to usos api endpoints" + }, + { + "name": "plannaplan.apikey", + "type": "java.lang.String", + "description": "Api consumer key" + }, + { + "name": "plannaplan.apisecret", + "type": "java.lang.String", + "description": "Api consumer secret" } ] }